// Login button text (either "Aanmelden" or "Afmelden")
buttonText = document.getElementsByTagName("span")[0].innerHTML;
// Dialog text
dialogText = document.querySelectorAll(".dialog_content")[1].innerHTML;

if (dialogText.indexOf("Onjuiste") == -1) {

	if (buttonText.indexOf("Aanmelden") != -1) {
		// Load settings from storage
		chrome.storage.sync.get(null, function(o) {
		  if (!o.username || !o.password) {
		  	// Exit if no credentials saved
		  	alert('You still need to save your username and password in the options of Yelo AutoLogin.');
		  } else {
		  	// Create listener to enter credentials when popup is loaded
		  	document.getElementById("dialog").addEventListener('DOMSubtreeModified',
		  		function(){
		  			document.getElementById("username").value = o.username;
		  			document.getElementById("password").value = o.password;
		  			// Click the submit button
		  			document.getElementById("btn_login").click();
		  		}, false);
		  }
		});
		
		// Click the login button
		document.querySelectorAll(".square-button")[0].click();
	}

}
